<?php
	
autoLoader();

// display( $_REQUEST );
// display( $_POST ); exit;

if( false == isset( $_POST['Submit'] ) || false == valStr( $_POST['name'] ) ) { 
	$str = '';
	$str .= '<form name=myform method=post action=modules.php?file=hospital&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
	$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
	echo $str;
	exit;
}

if( true == isset( $_POST['operation'] ) && 'insert' == strtolower( $_POST['operation'] ) ) {
	
	$objBaseHospital 	= new BaseHospital();

	$objBaseHospital->setName( $_POST['name'] );
	$objBaseHospital->setDescription( $_POST['description'] );
	$objBaseHospital->setAddressLine1( $_POST['address_line1'] );
	$objBaseHospital->setAddressLine2( $_POST['address_line2'] );
	$objBaseHospital->setAddressLine3( $_POST['address_line3'] );
	$objBaseHospital->setArea( $_POST['area'] );
	$objBaseHospital->setCity( $_POST['city'] );
	$objBaseHospital->setPinCode( $_POST['pin_code'] );
	$objBaseHospital->setAddressDetails( $_POST['address_details'] );
	$objBaseHospital->setPrimaryPhoneNumber( $_POST['primary_phone_number'] );
	$objBaseHospital->setEmailAddress( $_POST['email_address'] );
	$objBaseHospital->setWebUrl( $_POST['web_url'] );
	$objBaseHospital->setAlternativeNumber( $_POST['alternative_number'] );

	
	if( 1 == $objBaseHospital->insert() ) {
		$str = '';
		$str .= '<form name=myform method=post action=modules.php?file=view_hospital&type=view&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
		$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
		echo $str;
		exit;
	}
} else if( true == isset( $_POST['operation'] ) && 'update' == strtolower( $_POST['operation'] ) ) {
	$objHospital 		= new Hospital();
	$objBaseHospital 	= $objHospital->fetchHospitalById( $_POST['hospital_id'] );
	
	$objBaseHospital->setName( $_POST['name'] );
	$objBaseHospital->setDescription( $_POST['description'] );
	$objBaseHospital->setAddressLine1( $_POST['address_line1'] );
	$objBaseHospital->setAddressLine2( $_POST['address_line2'] );
	$objBaseHospital->setAddressLine3( $_POST['address_line3'] );
	$objBaseHospital->setArea( $_POST['area'] );
	$objBaseHospital->setCity( $_POST['city'] );
	$objBaseHospital->setPinCode( $_POST['pin_code'] );
	$objBaseHospital->setAddressDetails( $_POST['address_details'] );
	$objBaseHospital->setPrimaryPhoneNumber( $_POST['primary_phone_number'] );
	$objBaseHospital->setEmailAddress( $_POST['email_address'] );
	$objBaseHospital->setWebUrl( $_POST['web_url'] );
	$objBaseHospital->setAlternativeNumber( $_POST['alternative_number'] );
	if( 1 == $objBaseHospital->update() ) {
		$str = '';
		$str .= '<form name=myform method=post action=modules.php?file=view_hospital&type=view&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
		$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
		echo $str;
		exit;
	}
}

?>